package com.wms.web.controller.system;

import com.wms.common.core.controller.BaseController;
import com.wms.common.core.domain.AjaxResult2;
import com.wms.common.core.page.TableDataInfo;
import com.wms.system.domain.SysRouteIndividuationConfig;
import com.wms.system.domain.SysRouteSearchConfig;
import com.wms.system.domain.SysTableConfig;
import com.wms.system.domain.SysTableConfigMultilingual;
import com.wms.system.domain.po.SysTableConfigPo;
import com.wms.system.domain.vo.QueryTableLabelConfigVo;
import com.wms.system.domain.vo.SysTableConfigVo;
import com.wms.system.service.ISysTableConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "前端页面表格配置")
@RestController
@RequestMapping("/sys/tableConfig")
@RequiredArgsConstructor
public class SysTableConfigController extends BaseController {

    private final ISysTableConfigService tableConfigService;

    @GetMapping("/list")
    @ApiOperation("获取前端页面表格配置查询列表(后台维护查询)")
//    @PreAuthorize("@ss.hasPermi('table:config:list')")
    public TableDataInfo<SysTableConfig> getTableConfigList(SysTableConfigVo tableConfigVo){
        startPage();
        List<SysTableConfig> tableConfigs = tableConfigService.getTableConfigList(tableConfigVo);
        return getDataTable(tableConfigs);
    }

    /**
     * 初始化前端页面表格配置
     */
    @PostMapping("/initialization")
    @ApiOperation("初始化前端页面表格配置(后台维护新增)")
//    @PreAuthorize("@ss.hasPermi('table:config:initialization')")
    public AjaxResult2<Void> initialization(@Validated @RequestBody SysTableConfigVo tableConfigVo) {
        tableConfigService.initialization(tableConfigVo);
        return success2();
    }

    /**
     * 前端页面表格配置新增
     */
    @PostMapping("/tableConfigAdd")
    @ApiOperation("前端页面表格配置新增(后台维护新增字段)")
//    @PreAuthorize("@ss.hasPermi('table:config:add')")
    public AjaxResult2<Void> tableConfigAdd(@Validated @RequestBody SysTableConfig tableConfigVo) {
        tableConfigService.tableConfigAdd(tableConfigVo);
        return success2();
    }

    /**
     * 删除
     */
    @GetMapping("/del/{id}")
    @ApiOperation("删除(后台维护删除)")
//    @PreAuthorize("@ss.hasPermi('table:config:del')")
    public AjaxResult2<Void> del(@PathVariable String id) {
        tableConfigService.del(id);
        return success2();
    }

    /**
     * 编辑
     */
    @PostMapping("/edit")
    @ApiOperation("编辑(后台维护编辑)")
//    @PreAuthorize("@ss.hasPermi('table:config:edit')")
    public AjaxResult2<Void> edit(@RequestBody SysTableConfigVo sysTableConfigVo) {
        tableConfigService.edit(sysTableConfigVo);
        return success2();
    }



    /**
     * 多语言
     */
    @GetMapping("/getMultilingual/{id}")
    @ApiOperation("获取多语言列表")
//    @PreAuthorize("@ss.hasPermi('table:multilingual:list')")
    public AjaxResult2<List<SysTableConfigMultilingual>> getMultilingual(@PathVariable String id) {
        List<SysTableConfigMultilingual> tableConfigMultilinguals = tableConfigService.getMultilingual(id);
        return success2(tableConfigMultilinguals);
    }

    /**
     * 多语言编辑
     */
    @PostMapping("/editMultilingual")
    @ApiOperation("多语言编辑")
//    @PreAuthorize("@ss.hasPermi('table:multilingual:edit')")
    public AjaxResult2<Void> editMultilingual(@Validated @RequestBody SysTableConfigMultilingual sysTableConfigMultilingual) {
        tableConfigService.editMultilingual(sysTableConfigMultilingual);
        return success2();
    }

    /**
     * 多语言新增
     */
    @PostMapping("/addMultilingual")
    @ApiOperation("多语言新增")
//    @PreAuthorize("@ss.hasPermi('table:multilingual:add')")
    public AjaxResult2<Void> addMultilingual(@Validated @RequestBody SysTableConfigMultilingual sysTableConfigMultilingual) {
        tableConfigService.addMultilingual(sysTableConfigMultilingual);
        return success2();
    }


    /**
     * 多语言
     */
    @PostMapping("/getMultilingual")
    @ApiOperation("获取前端页面表格配置（多语言）")
//    @PreAuthorize("@ss.hasPermi('table:multilingual:config')")
    public AjaxResult2<List<SysTableConfigPo>> getTableLabelConfig(@RequestBody QueryTableLabelConfigVo configVo) {
        List<SysTableConfigPo> sysTableConfigPoList = tableConfigService.getTableLabelConfig(configVo);
        return success2(sysTableConfigPoList);
    }

//    @ApiOperation("添加个性化")
//    @PostMapping("/addIndividuation")
//    @PreAuthorize("@ss.hasPermi('route:individuation:add')")
//    public AjaxResult2<Void> addRouteIndividuation(@Validated @RequestBody SysRouteIndividuationConfig individuationConfig) {
//        tableConfigService.addRouteIndividuation(individuationConfig);
//        return success2();
//    }

    @ApiOperation("保存个性化")
    @PostMapping("/saveIndividuation")
//    @PreAuthorize("@ss.hasPermi('route:individuation:save')")
    public AjaxResult2<Void> saveRouteIndividuation(@Validated @RequestBody SysRouteIndividuationConfig individuationConfig) {
        tableConfigService.saveRouteIndividuation(individuationConfig);
        return success2();
    }

    @ApiOperation("获取个性化")
    @PostMapping("/getIndividuation")
//    @PreAuthorize("@ss.hasPermi('route:individuation:get')")
    public AjaxResult2<SysRouteIndividuationConfig> getIndividuation(@RequestBody SysRouteIndividuationConfig individuationConfig) {
        SysRouteIndividuationConfig config = tableConfigService.getIndividuation(individuationConfig);
        return success2(config);
    }

    @ApiOperation("保存搜索个性化")
    @PostMapping("/saveSearch")
//    @PreAuthorize("@ss.hasPermi('route:search:save')")
    public AjaxResult2<Void> saveRouteSearch(@Validated @RequestBody SysRouteSearchConfig searchConfig) {
        tableConfigService.saveRouteSearch(searchConfig);
        return success2();
    }

    @ApiOperation("获取搜索个性化")
    @PostMapping("/getRouteSearch")
//    @PreAuthorize("@ss.hasPermi('route:search:get')")
    public AjaxResult2<SysRouteSearchConfig> getRouteSearch(@RequestBody SysRouteSearchConfig searchConfig) {
        SysRouteSearchConfig config = tableConfigService.getRouteSearch(searchConfig);
        return success2(config);
    }
}
